//
//  LoginViewController.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/17.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "LoginViewController.h"

@interface LoginViewController ()

@property (nonatomic, strong) UIImageView *logoView;
@property (nonatomic, strong) UIImageView *logoLabel;
@property (nonatomic, strong) UITextField *accountTF;
@property (nonatomic, strong) UITextField *passwordTF;
@property (nonatomic, strong) UIButton  *loginButton;

@end

@implementation LoginViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    [self setupUI];
}

- (void)viewDidDisappear:(BOOL)animated{

    [super viewDidDisappear:animated];
    [self.view endEditing:YES];
}

- (void)setupUI{
    self.title = @"登录";
    
    [self.view addSubview:self.logoView];
    [self.view addSubview:self.logoLabel];
    [self.view addSubview:self.accountTF];
    [self.view addSubview:self.passwordTF];
    [self.view addSubview:self.loginButton];
    
    //设置布局
    CGFloat padding = (SCREEN_WIDTH == 320)?10:70;
    
    [self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(64+padding);
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(70, 90));
        
    }];
    
    [self.logoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.logoView.mas_bottom).offset(2);
        make.centerX.equalTo(self.logoView);
        make.size.mas_equalTo(CGSizeMake(70, 45));
    }];
    
    [self.accountTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.logoLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(35);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
    }];
    
    [self.passwordTF mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.accountTF.mas_bottom).offset(20);
        make.height.mas_equalTo(35);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
    }];
    
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordTF.mas_bottom).offset(30);
        make.height.mas_equalTo(45);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
    }];
    
}

#pragma mark
#pragma mark - 点击事件
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.view endEditing:YES];
}

#pragma mark
#pragma mark - 懒加载登录view
-(UIImageView *)logoView{

    if (_logoView == nil) {
        _logoView = [[UIImageView alloc]init];
        _logoView.image = [UIImage imageNamed:@"product_img_logo_nor.png"];
    }
    return _logoView;
}

- (UIImageView *)logoLabel{

    if (_logoLabel == nil) {
        _logoLabel = [[UIImageView alloc]init];
        _logoLabel.image = [UIImage imageNamed:@"product_text_logo_nor.png"];
        
    }
    return _logoLabel;
}

-(UITextField *)accountTF{

    if (_accountTF == nil) {
        _accountTF = [[UITextField alloc]init];
        _accountTF.placeholder = @"请输入账户";
        _accountTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _accountTF.borderStyle = UITextBorderStyleRoundedRect;
    }
    return  _accountTF;
}

- (UITextField *)passwordTF{

    if (_passwordTF == nil) {
        _passwordTF = [[UITextField alloc]init];
        _passwordTF.placeholder = @"请输入密码";
        _passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _passwordTF.borderStyle = UITextBorderStyleRoundedRect;
    }
    return _passwordTF;
}

-(UIButton *)loginButton{

    if (_loginButton == nil) {
        _loginButton = [[UIButton alloc]init];
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
        _loginButton.backgroundColor = kThemeColor;
        _loginButton.titleLabel.font = FONT(20);
    }
    return _loginButton;
}
@end
